package day1206_2;
class Test2{
    public static void main(String args[]){
        Shop2 t1 = new Shop2();
        Shop2 t2 = new Shop2();

        t1.start();
        t2.start();
    }
}

class Shop2 extends  Thread{
    private int beans = 20;
    public void run(){
        while(true){
            if(beans==0)
                throw new RuntimeException("没有豆子辣");	//由于没有进行异常处理，beans为0时会导致直接中断程序
            Thread.yield();						//将线程让出，用来模拟出现bug时的情况
            System.out.println("拿走了一颗，还剩"+beans+"颗。");
            beans--;
        }
    }
}